// pages/contact/contact.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    markers: [{
      iconPath: "../image/location.png",
      id: 0,
      latitude: '',
      longitude: '',
      width: 22,
      height: 22,
      fontSize: 40
    }],
    latitude: '',
    longitude: '',
    name: "吉海科技",
    address: '', // 公司地址
    contact: '', // 电话信息
    mail: '', // 邮箱
    copyright: [] // 版权信息
  },
  markertap(e) {
    // console.log(e)
  },
  click: function (e) {
    wx.openLocation({
      latitude: parseFloat(this.data.latitude),
      longitude: parseFloat(this.data.longitude),
      scale: 18,
      name: this.data.name,
      address: this.data.address
    })
  },
  tel: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.contact,
    })
  },
  // 分享小程序
  onShareAppMessage: function () {
    return {
      title: '专业的移动电子商务解决方案服务商',
      path: '/pages/index/index',
      imageUrl: '/pages/image/logo.png'
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSystemSetting()
  },
  // 获取后台配置信息
  getSystemSetting () {
    app.api.systemSetting({}, res => {
      if (res.status) {
        const info = res.data
        if (info.website_name) {
          // 设置tab页title
          wx.setNavigationBarTitle({
            title: info.website_name
          })
          this.setData({name: info.website_name})
        }
        if (info.website_contact) {
          this.setData({ contact: info.website_contact})
        }
        if (info.website_copyright) {
          let copyright = info.website_copyright.split('|')
          this.setData({copyright: copyright})
        }
        if (info.website_mail) {
          this.setData({mail: info.website_mail})
        }
        if (info.website_address) {
          this.setData({address: info.website_address})
        }
        if (info.website_location) {
          let location = info.website_location.split(',')
          this.setData({
            latitude: location[0],
            longitude: location[1]
          })
          let lat = "markers[" + 0 + "].latitude"
          let long = "markers[" + 0 + "].longitude"
          this.setData({
            [lat]: location[0],
            [long]: location[1]
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})